Home > Java Programming > Variables and Loops > Questions and Answers
01. |
What is the output for the below code ? 1. public class A { 2. int add(int i, int j){ 3. return i+j; 4. } 5.} 6.public class B extends A{ 7. public static void main(String argv[]){ 8. short s = 9; 9. System.out.println(add(s,6)); 10. } 11.} | |||||||||||
|
02. |
What is the output for the below code ? public class A { int k; boolean istrue; static int p; public void printValue() { System.out.print(k); System.out.print(istrue); System.out.print(p); } } public class Test{ public static void main(String argv[]){ A a = new A(); a.printValue(); } } | |||||||||||
|
03. |
What is the output for the below code ? public class Test{ int _$; int $7; int do; public static void main(String argv[]){ Test test = new Test(); test.$7=7; test.do=9; System.out.println(test.$7); System.out.println(test.do); System.out.println(test._$); } } | |||||||||||
|
04. |
What is the output for the below code ? public class A { static{System.out.println("static");} { System.out.println("block");} public A(){ System.out.println("A"); } public static void main(String[] args){ A a = new A(); }} | |||||||||||
|
05. |
What is the output for the below code ? 1. public class Test { 2. public static void main(String[] args){ 3. int i = 010; 4. int j = 07; 5. System.out.println(i); 6. System.out.println(j); 7. } 8. } | |||||||||||
|
06. |
What is the output for the below code ? 1. public class Test { 2. public static void main(String[] args){ 3. byte b = 6; 4. b+=8; 5. System.out.println(b); 6. b = b+7; 7. System.out.println(b); 8. } 9. } | |||||||||||
|
07. |
You have a java file name Test.java inside src folder of javaproject directory. You have also classes folder inside javaproject directory. you have issued below command from command prompt. cd javaproject Which of the below command puts Test.class file inside classes folder ? | |||||||||||
|
08. |
You have two class files name Test.class and Test1.class inside javaproject directory. Test.java source code is : public class Test{ public static void main (String[] args){ System.out.println("Hello Test"); } } Test1.java source code is : public class Test1{ public static void main (String[] args){ System.out.println("Hello Test1"); } } you have issued below commands from command prompt. cd javaproject java Test Test1 What is the output ? | |||||||||||
|
09. |
You have a java file name Test.java . Test.java needs access to a class contained in app.jar in "exam" directory. Which of the follwing command set classpath to compile clean? | |||||||||||
|
10. |
What happens when the following code is compiled and run. Select the one correct answer. for(int i = 2; i < 4; i++) for(int j = 2; j < 4; j++) if(i < j) assert i!=j : i; | |||||||||||
|